package cn.edu.seu.ssny.service;


import cn.edu.seu.ssny.entity.*;
import cn.edu.seu.ssny.service.support.IBaseService;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Optional;

public interface IDeviceDataStdService extends IBaseService<DeviceDataStd, Integer> {
    Optional<DeviceDataStd> findFirstByDeviceOrderByCreateTimeDesc(Device device);

    Optional<DeviceDataStd> findByDeviceAndCreateTime(Device device, Date createTime);

    List<DeviceDataStd> findAllByDeviceAndCreateTimeBetween(Device device, Date start, Date end);

    List<DeviceDataStd> findAllByDeviceAndCreateTimeBetweenOrderByCreateTimeAsc(Device device, Date start, Date end);

    void modifyDate(DeviceDataStd deviceDataStd, DeviceData deviceData);

    void create(DeviceData deviceData, Date createTime);

    void newDataProcess(DeviceData deviceData);

    /*删除 下面代表的表格中  interval天之前 并且不满足该表存储数据要求的所有数据*/
    void deleteFromYear();

    void deleteFromMonth();

    void deleteFromDay(int interval);

    void deleteFromHour(int interval);

    /**
     *功能描述:
     *<按照时间Asc查询出startDate和endDate之间的数据，采集点位deviceIds
     * @param deviceIds
     * @param timeMode
     * @param startDate
     * @param endDate
     * @return
     */
    List<DeviceDataStd> findAllByDeviceIdsInAndCreateTimeBetweenOrderByCreateTimeASC(List<Integer> deviceIds, int timeMode, Date startDate, Date endDate);

    /**
     * 功能描述:
     * <按照时间Asc查询出startDate和endDate之间的数据，采集点位devices
     * @param devices
     * @param timeMode
     * @param startDate
     * @param endDate
     * @return
     */
    List<DeviceDataStd> findAllByDeviceInAndCreateTimeBetweenOrderByCreateTimeASC(List<Device> devices, int timeMode, Date startDate, Date endDate);

    Double findEquipmentDeviceDataStd(Equipment equipment, String deviceType, Date createTime);

    Map<String, List<Double>> getCopCH(List<Date> timeList, Project project, String mode, String CH);

    Map<String, List<Double>> getCopCHAll(List<Date> timeList, Project project, String mode);

    Map<String, List<Double>> getPumpEff(List<Date> timeList, Project project, String mode);

    Double getPumpCoefficient(List<Date> timeList, Project project, String pumpType);

    Map<String, Object> getHeatBalanceCoefficient(List<Date> timeList, Project project);

    Map<String, List<Double>> getBalanceTemp(List<Date> timeList, Project project, String mode);

    Map<String, List<Double>> getBuriedPipeLine(List<Date> timeList, Project project, String mode);

    /**
     * 功能描述:
     * <逐天统计devices中的采集点在某天之内的累计值
     * <例如 dates = [20210705000000,20210706000000,20210707000000,20210708050608当前时刻]  返回devices在20210705、20210706、20210707的采集值，以及20210708到目前为止的采集值
     * <当天采集值由当前最开始采集到的数据以及第二天最开始采集到的数据做差得到
     *
     * @param devices
     * @param dates
     * @param timeMode
     * @return
     */
    List<Double> getDataByDevicesAndDates(List<Device> devices, List<Date> dates, int timeMode);

    /**
     * 功能描述:
     * <逐天统计deviceIds中的采集点在某天之内的累计值
     * <例如 dates = [20210705000000,20210706000000,20210707000000,20210708050608当前时刻]  返回devices在20210705、20210706、20210707的采集值，以及20210708到目前为止的采集值
     * <当天采集值由当前最开始采集到的数据以及第二天最开始采集到的数据做差得到
     *
     * @param deviceIds
     * @param dates
     * @param timeMode
     * @return
     */
    List<Double> getDataByDeviceIdsAndDates(List<Integer> deviceIds, List<Date> dates, int timeMode);

    /*获取到每个时间点的累积值*/
    Map<Date, Double> getTotalDataByDevicesAndDates(List<Device> devices, List<Date> dates, int mode);

    /*所有项目总和 每天供冷/供暖能耗统计 mode=0表示供冷 mode=1表示供暖*/
    List<Double> getPowerCostByDaysAndEquipmentTypes(List<Date> dates, List<String> equipmentTypes);

    /**
     * 功能描述:
     * <计算系统能效-指定项目
     * <eneryEquipment的制冷或者供暖量除以powercostEquipements的能耗总和(逐天计算，指定项目)
     *
     * @param project
     * @param timeList
     * @param powercostEquipementTypes
     * @param energyEquipmentTypes
     * @param mode
     * @param timeMode
     * @return
     */
    List<Double> getSCOPByProject(Project project, List<Date> timeList, List<String> powercostEquipementTypes, List<String> energyEquipmentTypes, int mode, int timeMode);

    /**
     * 功能描述：
     * <计算系统能效-不指定项目
     * <eneryEquipment的制冷或者供暖量除以powercostEquipements的能耗总和(逐天计算，不指定项目)
     *
     * @param dates
     * @param powercostEquipementTypes 统计能耗的设备集合
     * @param energyEquipmentTypes     统计制冷或者供暖的能耗集合
     * @param mode                     制冷模式或者供暖模式
     * @param timeMode
     * @return
     */
    List<Double> getSCOP(List<Date> dates, List<String> powercostEquipementTypes, List<String> energyEquipmentTypes, int mode, int timeMode);

    /**
     * 功能描述:
     * <计算机组能效-指定项目
     * <eneryEquipment的制冷或者供暖量除以powercostEquipements的能耗总和(逐天计算，指定项目)
     *
     * @param project
     * @param dates
     * @param powercostEquipementTypes
     * @param energyEquipmentTypes
     * @param mode
     * @param timeMode
     * @return
     */
    List<Double> getCOPByProject(Project project, List<Date> dates, List<String> powercostEquipementTypes, List<String> energyEquipmentTypes, int mode, int timeMode);

    /**
     * 功能描述:
     * 不指定项目，根据设备类型，返回每个类型设备的能耗
     *
     * @param equipmentTypes
     * @return
     */
    List<Double> getPowerCostByEquipmentTypes(List<String> equipmentTypes);

    /**
     * 功能描述:
     * 指定项目，根据设备类型，返回每个类型设备的能耗
     *
     * @param project
     * @param equipmentTypes
     * @return
     */
    List<Double> getPowerCostByEquipmentTypeAndProject(Project project, List<String> equipmentTypes);


    /*计算可再生能源利用量*/
    Double getRenewableEnery();

    /*计算节约标煤量*/
    Double getSaveCoal();

    /*计算碳减排量*/
    Double getCarbinReduction();


}

